Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#12254: cppcheck.cfg can't be loaded from relative paths anymore #5753

Closed
wants to merge 4 commits into from

Conversation

olabetskyi
Copy link
Collaborator

Hot fix

@firewave
Copy link
Collaborator

Well - this is not really a hotfix but a partial revert..

But I checked the code and it is unlikely to cause any issues. 👍

I have local changes which will address this in a more proper way very soon.

@danmar
Copy link
Owner

danmar commented Dec 11, 2023

so the "format" complained. check the "runformat" script for instructions how to compile proper uncrustify version..

test/cli/test-other.py Outdated Show resolved Hide resolved
test/cli/test-other.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@firewave firewave left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Un-approved. I didn't look at the test. The usage of relative paths is obvious not good. It already has lots of problems with depending on certain locations. We shouldn't make it worse.

@danmar
Copy link
Owner

danmar commented Dec 11, 2023

Un-approved. I didn't look at the test. The usage of relative paths is obvious not good. It already has lots of problems with depending on certain locations. We shouldn't make it worse.

Could you elaborate, I don't understand how this makes it worse. It does solve the bug I've seen.

My intention is that cppcheck.cfg is put in the same folder as the cppcheck binary and it's not something users should touch/maintain.

@firewave
Copy link
Collaborator

Could you elaborate, I don't understand how this makes it worse. It does solve the bug I've seen.

I was referring to the relative path in the added test. Sorry for not being clear about that.

Also the other issues I was referring to is that the test/cli tests can only be executed when inside the test/cli whereas it should be runnable from any location (I already have fixes for some of the tests).

@danmar
Copy link
Owner

danmar commented Dec 11, 2023

Also the other issues I was referring to is that the test/cli tests can only be executed when inside the test/cli whereas it should be runnable from any location (I already have fixes for some of the tests).

Ah.. yes I agree about that.

test/testcmdlineparser.cpp Outdated Show resolved Hide resolved
product_name = 'Cppcheck Premium ' + str(time.time())

test_cfg = lookup_cppcheck_exe()
if(test_cfg.endswith('.exe')):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very bad and dangerous. If the test gets aborted beforehand you have a stray file which will infer with your system. It might also override a file the user might have created for themselves.
A better way to test this would probably be to copy the folder where the binary is located in into a new folder within tmpdir.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already do something similar in other tests with the local cppcheck_local() - which is not something I would encourage. I will try to provide a shared helper which will generate a copy for the execution and update the existing tests.

""".replace('NAME', product_name))

if os.path.isfile('cppcheck'):
os.chdir('test/cli')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just no. If you need to change the directory for running a process please pass the cwd parameter to the call. cppcheck() might already expose that. If it doesn't please pass that through as a an additional positional parameter.

assert stdout == product_name + '\n'
assert stderr == ''

os.remove(test_cfg)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you put the folder as suggested into tmpdir this is no longer necessary.

f.write("""
{
"addons": [],
"productName": "NAME",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use {} placeholder and call format() on the string instead. You can also get rid of the product_name variable if you do not use it in any other way and just fold it in here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's also used for an assert on line 863.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's also used for an assert on line 863.

I knew I overlooked it somehow.

Still you should use format() instead of replace().

@danmar
Copy link
Owner

danmar commented Dec 12, 2023

This blocks release testing of cppcheck together with the premium addon.. I want to merge the fix now and then I will merge the test later when it's acceptable..

@danmar danmar closed this Dec 12, 2023
@firewave
Copy link
Collaborator

This blocks release testing of cppcheck together with the premium addon.. I want to merge the fix now and then I will merge the test later when it's acceptable..

As mentioned in other comments I have local changes which refactor this which are very straight forward ... except for the GUI usage of it which is why I didn't post an PR for it yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants